#ifndef _YYTHREAD_H_
#define _YYTHREAD_H_

#include "Common.h"

#define WAIT_TIME	300
typedef unsigned (WINAPI *THREAD_PROC) ( void * );

class YYThread
{
public:
	HANDLE hThread;

	int Create(
		THREAD_PROC start_address,
		void *arg,
		unsigned initflag = CREATE_SUSPENDED)
	{
		hThread = (HANDLE)_beginthreadex(NULL,0,start_address,arg,initflag,NULL);
		if( hThread == NULL )
		{
			return 1;
		}
		return 0;
	}

	int Resume()
	{
		ResumeThread(hThread);
		return 0;
	}
	int Suspend()
	{
		SuspendThread(hThread);
		return 0;
	}
	int Terminate()
	{
		if( WaitForSingleObject(hThread,WAIT_TIME) != WAIT_OBJECT_0 )
		{
			TerminateThread(hThread,0);
		}
		Close();
		return 0;
	}
	int WaitTerminate()
	{
		WaitForSingleObject(hThread,INFINITE);
		Close();
		return 0;
	}
	int Close()
	{
		CloseHandle(hThread);
		return 0;
	}
	
};

#endif